package order

import (
	"context"
	"gitee.com/tietang/terrace-go/v2/base/plugin"
)

var _ CreateOrderDomainExt = new(CreateOrderDomainExtProxy)

func GetCreateOrderDomainExtProxy() *CreateOrderDomainExtProxy {
	ext := &CreateOrderDomainExtProxy{}
	return ext
}

type CreateOrderDomainExtProxy struct {
	plugin.Plugin `pluginId:"CreateOrderDomainPluginId"`
	plugin.PluginId
	plugin.RuleChecker
	exts        []CreateOrderDomainExt
	isInit      bool
	ExtExecutor plugin.PluginExecutor
}

func (o *CreateOrderDomainExtProxy) CanExe(in interface{}) bool {
	return true
}

func (o *CreateOrderDomainExtProxy) PluginCode() string {
	return CreateOrderDomainPluginId
}

func (o *CreateOrderDomainExtProxy) OnValidate(ctx context.Context, in *Order) error {
	return o.ExtExecutor.Execute(ctx, o.PluginCode(), in, func(pluginInterface interface{}) error {
		err := pluginInterface.(CreateOrderDomainExt).OnValidate(ctx, in)
		return err
	})
}

func (o *CreateOrderDomainExtProxy) PreSave(ctx context.Context, in *Order) error {
	return o.ExtExecutor.Execute(ctx, o.PluginCode(), in, func(pluginInterface interface{}) error {
		err := pluginInterface.(CreateOrderDomainExt).PreSave(ctx, in)
		return err
	})
}
